<template>
    <div>
        <div class="table_box">
            <tyTable :searchFlag="false"
                     :listApi="$api.listHttpInfo"
                     :deleteApi="$api.deleteUser"
                     :delete-flag="false"
                     :afterList="afterList"
                     :columnWidth="220"
                     :fixParamFunc="fixParamFunc"
                     :openDrawer="openDrawer" ref="tyTable">
                <template v-slot:search="{ param}">

                </template>

                <!--            按钮-->
                <template v-slot:search-operation>
                    <el-button type="primary" @click="$router.go(-1)" icon="el-icon-back">返回</el-button>
                </template>

                <template v-slot:table>
                    <el-table-column type="index" label="序号" align="center" width="52"></el-table-column>
                    <el-table-column prop="confInfoName" label="文件" width="120" align="center">
                        <template slot-scope="scope">
                            <div >{{name}}</div>
                        </template>
                    </el-table-column>
                    <el-table-column prop="listen" label="节点" width="120" align="center">
                        <template slot-scope="scope">
                            <div >http</div>
                        </template>
                    </el-table-column>
                    <el-table-column prop="text" label="配置" align="center">
                        <template slot-scope="scope">
                            <div class="limit-height">{{scope.row.text}}</div>
                        </template>
                    </el-table-column>

                </template>

                <template v-slot:extra="{row}">
                    <el-button @click="gotoServer(row)" type="text" size="small">
                        SERVER
                    </el-button>
                    <el-button @click="gotoUpstreamInfo(row)" type="text" size="small">
                        UPSTREAM
                    </el-button>
                </template>
            </tyTable>
        </div>

        <tyAddUpdate :model="formData"
                     :add-api="$api.addUser"
                     :update-api="$api.updateHttpInfo"
                     :dialogSize="'60%'"
                     ref="tyAddUpdate"
        >
            <el-form label-position="left" label-width="100px" :model="name" :rules="rules">
                <el-form-item label="文件:" prop="confInfoName">
                    <el-input v-model="formData.name" placeholder=""  clearable disabled
                              maxlength="300"></el-input>
                </el-form-item>

                <el-form-item label="内容">
                    <el-input v-model="formData.text" type="textarea" autosize placeholder=""
                    ></el-input>
                </el-form-item>

            </el-form>
        </tyAddUpdate>

    </div>
</template>

<script>
import {tyAddUpdateMixins, tyConfirmMixins} from "@/mixins/addEditFormMixins";

export default {
    name: "httpConfig",
    mixins: [tyAddUpdateMixins, tyConfirmMixins],
    data(){
        return{
            formData : {},
            loading:false,
            options: [],
            name : '',
            confInfoId : null,
            rules: {
            }
        }
    },
    methods : {
        getSelect(){
            this.$api.listConfInfo({page : 1 , limit : 1000}).then((res) => {
                this.options = []
                let array = res.records
                for(let item of array){
                    this.options.push({value : item.id, label : item.path})
                }
            })
        },
        gotoServer(row){
            this.$router.push({name : 'serverConfig' , query:{confInfoId:this.confInfoId }})
        },
        gotoUpstreamInfo(){
            this.$router.push({name : 'upstreamConfig' , query:{confInfoId:this.confInfoId }})
        },
        fixParamFunc(form){
            let confInfoId = this.$route.query.confInfoId
            this.name = this.$route.query.name
            if(confInfoId !=  null){
                this.confInfoId = confInfoId
                form.confInfoId = confInfoId
            }
        },
        afterList(array){
            for(let item of array){
                item.name = this.name
            }
        }
    },
    mounted() {
        this.getSelect()
    },

}

</script>
<style scoped lang="scss">
    .limit-height{
        height:50px;
    }
</style>